```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>微服务架构深度解析 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0,0,0,0.1);
        }
        .section-title {
            position: relative;
            padding-bottom: 1rem;
        }
        .section-title:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 60px;
            height: 3px;
            background: linear-gradient(90deg, #6e8efb, #a777e3);
        }
        .code-block {
            background-color: #f8f9fa;
            border-left: 4px solid #6e8efb;
            padding: 1rem;
            border-radius: 0 4px 4px 0;
        }
        .comparison-table {
            border-collapse: separate;
            border-spacing: 0;
            width: 100%;
        }
        .comparison-table th, .comparison-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #e0e0e0;
        }
        .comparison-table tr:hover td {
            background-color: #f5f7ff;
        }
        .comparison-table th {
            background-color: #f8f9fa;
            font-weight: 600;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 leading-tight">微服务架构深度解析</h1>
                    <p class="text-xl mb-8 opacity-90">探索现代化分布式系统的设计与实现</p>
                    <div class="flex flex-wrap gap-4">
                        <a href="#what-is-microservice" class="bg-white text-indigo-600 px-6 py-3 rounded-lg font-medium hover:bg-opacity-90 transition">了解微服务</a>
                        <a href="#spring-cloud" class="bg-white bg-opacity-20 px-6 py-3 rounded-lg font-medium hover:bg-opacity-30 transition">Spring Cloud</a>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="bg-white bg-opacity-20 p-6 rounded-xl backdrop-blur-sm">
                        <div class="mermaid">
                            graph LR
                            A[客户端] --> B[API Gateway]
                            B --> C[服务A]
                            B --> D[服务B]
                            B --> E[服务C]
                            C --> F[数据库A]
                            D --> G[数据库B]
                            E --> H[数据库C]
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- What is Microservice -->
    <section id="what-is-microservice" class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 section-title">微服务是什么</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-8">
                    <blockquote class="border-l-4 border-indigo-500 pl-4 mb-6 italic text-gray-700">
                        就目前而言，对于微服务业界并没有一个统一的、标准的定义。微服务架构是一种架构模式或者说是一种架构风格，它提倡将单一应用程序划分成一组小的服务，每个服务运行独立的自己的进程中，服务之间互相协调、互相配合，为用户提供最终价值。
                    </blockquote>
                    
                    <div class="flex items-center text-sm text-gray-500 mb-6">
                        <i class="fas fa-link mr-2"></i>
                        <span>参考链接: </span>
                        <a href="https://martinfowler.com/articles/microservices.html#MicroservicesAndSoa" class="text-indigo-600 ml-1 hover:underline" target="_blank">英文原文</a>
                        <span class="mx-2">|</span>
                        <a href="http://blog.cuicc.com/blog/2015/07/22/microservices/" class="text-indigo-600 hover:underline" target="_blank">中文翻译</a>
                    </div>
                    
                    <p class="mb-4">马丁·福勒对微服务的概述强调了几个关键点：</p>
                    <ul class="list-disc pl-6 space-y-2 mb-6">
                        <li>服务之间采用轻量级的通信机制互相沟通（通常是基于HTTP的RESTful API）</li>
                        <li>每个服务都围绕着具体业务进行构建</li>
                        <li>能够被独立地部署到生产环境</li>
                        <li>应尽量避免统一的、集中式的服务管理机制</li>
                        <li>可以根据业务上下文选择合适的语言、工具进行构建</li>
                    </ul>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 p-3 rounded-full mr-4">
                                <i class="fas fa-check-circle text-indigo-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-semibold">微服务特点</h3>
                        </div>
                        <ol class="list-decimal pl-6 space-y-3">
                            <li>围绕业务进行服务拆分</li>
                            <li>每个服务都是独立进程</li>
                            <li>服务间采用轻量级通信协议（HTTP REST通信）</li>
                            <li>中心化管理</li>
                            <li>可采用不同语言开发，使用独立数据库</li>
                        </ol>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 p-3 rounded-full mr-4">
                                <i class="fas fa-balance-scale text-indigo-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-semibold">微服务优缺点</h3>
                        </div>
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div>
                                <h4 class="font-medium text-green-600 mb-2">优点</h4>
                                <ul class="list-disc pl-5 space-y-1 text-sm">
                                    <li>开发简单、效率高</li>
                                    <li>小团队单独开发</li>
                                    <li>松耦合、功能明确</li>
                                    <li>多语言支持</li>
                                    <li>灵活部署</li>
                                    <li>独立数据存储</li>
                                </ul>
                            </div>
                            <div>
                                <h4 class="font-medium text-red-600 mb-2">缺点</h4>
                                <ul class="list-disc pl-5 space-y-1 text-sm">
                                    <li>分布式系统复杂性</li>
                                    <li>多服务运维难度</li>
                                    <li>系统部署依赖</li>
                                    <li>服务间通信成本</li>
                                    <li>数据一致性挑战</li>
                                    <li>集成测试难度大</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-6">
                    <h3 class="text-xl font-semibold mb-4">常见微服务架构</h3>
                    <div class="overflow-x-auto">
                        <table class="comparison-table">
                            <thead>
                                <tr>
                                    <th>公司</th>
                                    <th>架构名称</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>阿里</td>
                                    <td>Dubbo/HSF(分布式的高速框架，可以理解为第二代的Dubbo)</td>
                                </tr>
                                <tr>
                                    <td>京东</td>
                                    <td>JSF</td>
                                </tr>
                                <tr>
                                    <td>新浪</td>
                                    <td>Motan</td>
                                </tr>
                                <tr>
                                    <td>当当网</td>
                                    <td>DoubleX</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Spring Cloud -->
    <section id="spring-cloud" class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 section-title">Spring Cloud</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-8">
                    <h3 class="text-2xl font-semibold mb-4">什么是Spring Cloud</h3>
                    <p class="mb-6">Spring Cloud提供了一系列微服务开发的一站式解决方案，也是一系列主流框架的集合。在微服务架构中，需要几个基础的服务治理组件，包括服务注册与发现、服务消费、负载均衡、断路器、智能路由、配置管理等，由这几个基础组件相互协作，共同组建了一个简单的微服务系统，Spring Cloud就提供了这一系列的组件。</p>
                    
                    <div class="flex items-center text-sm text-gray-500 mb-6">
                        <i class="fas fa-link mr-2"></i>
                        <span>参考链接: </span>
                        <a href="https://spring.io/projects/spring-cloud" class="text-indigo-600 ml-1 hover:underline" target="_blank">Spring Cloud官网</a>
                        <span class="mx-2">|</span>
                        <a href="https://www.springcloud.cc/" class="text-indigo-600 hover:underline" target="_blank">中文网</a>
                        <span class="mx-2">|</span>
                        <a href="https://www.springcloud.cc/spring-cloud-netflix.html" class="text-indigo-600 hover:underline" target="_blank">中文文档</a>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-6">
                    <h3 class="text-xl font-semibold mb-4">Spring Cloud和Dubbo区别</h3>
                    <div class="overflow-x-auto">
                        <table class="comparison-table">
                            <thead>
                                <tr>
                                    <th>服务组件</th>
                                    <th>Dubbo</th>
                                    <th>Spring Cloud</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>服务注册中心</td>
                                    <td>Zookeeper</td>
                                    <td>Eureka</td>
                                </tr>
                                <tr>
                                    <td>服务调用方式</td>
                                    <td>RPC</td>
                                    <td>REST(基于HTTP的)</td>
                                </tr>
                                <tr>
                                    <td>服务监控</td>
                                    <td>Dubbo-monitor</td>
                                    <td>Spring-cloud-admin</td>
                                </tr>
                                <tr>
                                    <td>断路器</td>
                                    <td>不完善</td>
                                    <td>Spring-Cloud-netflix-Hystrix</td>
                                </tr>
                                <tr>
                                    <td>服务网关</td>
                                    <td>无</td>
                                    <td>Spring-Cloud-netflix-Zull/Getway</td>
                                </tr>
                                <tr>
                                    <td>配置中心</td>
                                    <td>无</td>
                                    <td>Spring-cloud-config</td>
                                </tr>
                                <tr>
                                    <td>服务跟踪</td>
                                    <td>无</td>
                                    <td>Spring-Cloud-Sleuth</td>
                                </tr>
                                <tr>
                                    <td>消息总线</td>
                                    <td>无</td>
                                    <td>Spring-Cloud-Bus</td>
                                </tr>
                                <tr>
                                    <td>数据流</td>
                                    <td>无</td>
                                    <td>Spring-Cloud-Stream</td>
                                </tr>
                                <tr>
                                    <td>批量任务</td>
                                    <td>无</td>
                                    <td>Spring-Cloud-Task</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4">Spring Cloud调用方式</h3>
                        <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692159155064-0548083f-a9f1-44ac-a559-40eb8596c9b8.png" alt="Spring Cloud调用方式" class="rounded-lg mb-4 w-full">
                        <p class="text-sm text-gray-600">Spring Cloud使用RESTful API实现服务之间通信</p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4">Dubbo调用方式</h3>
                        <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692159155162-2794f69b-df00-4e4a-9811-a01dcf668b20.png" alt="Dubbo调用方式" class="rounded-lg mb-4 w-full">
                        <p class="text-sm text-gray-600">Dubbo使用RPC实现服务之间通信</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Eureka -->
    <section id="eureka" class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 section-title">注册中心-Eureka</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-8">
                    <p class="mb-6">Eureka是Netflix出品的用于实现服务注册和发现的工具。Spring Cloud集成了Eureka，并提供了开箱即用的支持。其中，Eureka又可细分为Eureka Server和Eureka Client。</p>
                    
                    <div class="bg-gray-100 p-6 rounded-lg mb-6">
                        <div class="mermaid">
                            graph TB
                            subgraph Eureka集群
                                A[Eureka Server1]
                                B[Eureka Server2]
                                A -- 数据同步 --> B
                                B -- 数据同步 --> A
                            end
                            C[Application Service] -- 注册 --> A
                            D[Application Client] -- 获取服务列表 --> A
                            D -- 调用 --> C
                        </div>
                    </div>
                    
                    <h4 class="font-semibold mb-2">Eureka集群说明：</h4>
                    <ul class="list-disc pl-6 space-y-2 mb-6">
                        <li>处于不同节点的eureka通过Replicate进行数据同步</li>
                        <li>Application Service为服务提供者</li>
                        <li>Application Client为服务消费者</li>
                        <li>Make Remote Call完成一次服务调用</li>
                    </ul>
                    
                    <h3 class="text-xl font-semibold mb-4">Eureka原理</h3>
                    <img src="https://img-blog.csdnimg.cn/20190703102014756.png" alt="Eureka原理图" class="rounded-lg mb-4 w-full">
                    <p class="mb-4">服务启动后向Eureka注册，Eureka Server会将注册信息向其他Eureka Server进行同步，当服务消费者要调用服务提供者，则向服务注册中心获取服务提供者地址，然后会将服务提供者地址缓存在本地，下次再调用时，则直接从本地缓存中取，完成一次调用。</p>
                    <p class="mb-4">当服务注册中心Eureka Server检测到服务提供者因为宕机、网络原因不可用时，则在服务注册中心将服务置为DOWN状态，并把当前服务提供者状态向订阅者发布，订阅过的服务消费者更新本地缓存。</p>
                    <p>服务提供者在启动后，周期性（默认30秒）向Eureka Server发送心跳，以证明当前服务是可用状态。Eureka Server在一定的时间（默认90秒）未收到客户端的心跳，则认为服务宕机，注销该实例。</p>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4">搭建Eureka注册中心</h3>
                        <h4 class="font-medium mb-2">1. 搭建一个父工程-POM类型</h4>
                        <div class="code-block mb-4">
                            <pre><code class="language-xml">&lt;!-- SprintBoot 父工程依赖 -->
&lt;parent>
   &lt;groupId>org.springframework.boot&lt;/groupId>
   &lt;artifactId>spring-boot-starter-parent&lt;/artifactId>
   &lt;version>2.1.7.RELEASE&lt;/version>
   &lt;relativePath/> &lt;!-- lookup parent from repository -->
&lt;/parent></code></pre>
                        </div>
                        
                        <h4 class="font-medium mb-2">2. 创建一个SpringBoot Web项目</h4>
                        <div class="code-block mb-4">
                            <pre><code class="language-java">@SpringBootApplication
@EnableEurekaServer
public class SpringcloudEurekaServerApplication {
   public static void main(String[] args) {
      SpringApplication.run(SpringcloudEurekaServerApplication.class, args);
   }
}</code></pre>
                        </div>
                        
                        <h4 class="font-medium mb-2">3. 配置</h4>
                        <div class="code-block">
                            <pre><code>#关闭eureka自动注册服务
eureka.client.register-with-eureka=false
#禁止当前微服务调用其他微服务
eureka.client.fetch-registry=false
#eureka注册中心地址
eureka.client.service-url.defaultZone=http://localhost:8080/eureka
#配置应用程序的名称
spring.application.name=eureka-server</code></pre>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4">搭建微服务-提供者</h3>
                        <h4 class="font-medium mb-2">1. 创建一个SpringBoot项目继承父工程</h4>
                        
                        <h4 class="font-medium mb-2">2. 自定义一个Controller</h4>
                        <div class="code-block mb-4">
                            <pre><code class="language-java">@RequestMapping(value = "/hello")
public class HelloController {

    @RequestMapping(value = "/test1/{id}")
    @ResponseBody
    public String test1(@PathVariable  Integer id){
        System.out.println("HelloController.test1 id:"+id);
        return "id:"+id;
    }
}</code></pre>
                        </div>
                        
                        <h4 class="font-medium mb-2">3. 配置</h4>
                        <div class="code-block mb-4">
                            <pre><code>server.port=8081
#eureka服务中心地址
eureka.client.service-url.defaultZone=http://localhost:8080/eureka
# 微服务提供者名称
spring.application.name=eureka-provide</code></pre>
                        </div>
                        
                        <h4 class="font-medium mb-2">4. 主启动类</h4>
                        <div class="code-block">
                            <pre><code class="language-java">@EnableEurekaClient
@SpringBootApplication(scanBasePackages = "com.qf")
public class EurekaProviderApplication {
   public static void main(String[] args) {
      SpringApplication.run(EurekaProviderApplication.class, args);
   }
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Service Consumers -->
    <section id="service-consumers" class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 section-title">服务消费者</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="bg-blue-100 p-3 rounded-full mr-4">
                                <i class="fas fa-exchange-alt text-blue-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-semibold">Ribbon消费者</h3>
                        </div>
                        
                        <h4 class="font-medium mb-2">1. 添加依赖</h4>
                        <div class="code-block mb-4">
                            <pre><code class="language-xml">&lt;dependency>
   &lt;groupId>org.springframework.cloud&lt;/groupId>
   &lt;artifactId>spring-cloud-starter-netflix-eureka-client&lt;/artifactId>
&lt;/dependency>
&lt;dependency>
   &lt;groupId>org.springframework.cloud&lt;/groupId>
   &lt;artifactId>spring-cloud-starter-netflix-ribbon&lt;/artifactId>
&lt;/dependency></code></pre>
                        </div>
                        
                        <h4 class="font-medium mb-2">2. 主启动类</h4>
                        <div class="code-block mb-4">
                            <pre><code class="language-java">@EnableEurekaClient
@SpringBootApplication(scanBasePackages = "com.qf")
public class EurekaConsumerRibbonApplication {

   public static void main(String[] args) {
      SpringApplication.run(EurekaConsumerRibbonApplication.class, args);
   }

   @Bean
   @LoadBalanced // 负载均衡
   public RestTemplate restTemplate(){
      return new RestTemplate();
   }

    @Bean // 随机的负载均衡方式
    public IRule getRule(){
       return new RandomRule();
    }
}</code></pre>
                        </div>
                        
                        <h4 class="font-medium mb-2">3. 负载均衡策略</h4>
                        <ul class="list-disc pl-5 space-y-1 text-sm">
                            <li><strong>RandomRule</strong> - 随机策略</li>
                            <li><strong>RoundRobinRule</strong> - 轮询策略（默认）</li>
                            <li><strong>RetryRule</strong> - 重试策略</li>
                            <li><strong>BestAvailableRule</strong> - 最低并发策略</li>
                            <li><strong>AvailabilityFilteringRule</strong> - 可用过滤策略</li>
                            <li><strong>ResponseTimeWeightedRule</strong> - 响应时间加权重策略</li>
                            <li><strong>ZoneAvoidanceRule</strong> - 区域权重策略</li>
                        </ul>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="bg-purple-100 p-3 rounded-full mr-4">
                                <i class="fas fa-code text-purple-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-semibold">Feign消费者</h3>
                        </div>
                        
                        <h4 class="font-medium mb-2">1. 添加依赖</h4>
                        <div class="code-block mb-4">
                            <pre><code class="language-xml">&lt;dependency>
   &lt;groupId>org.springframework.cloud&lt;/groupId>
   &lt;artifactId>spring-cloud-starter-netflix-eureka-client&lt;/artifactId>
&lt;/dependency>
&lt;dependency>
   &lt;groupId>org.springframework.cloud&lt;/groupId>
   &lt;artifactId>spring-cloud-starter-openfeign&lt;/artifactId>
&lt;/dependency></code></pre>
                        </div>
                        
                        <h4 class="font-medium mb-2">2. 主启动类</h4>
                        <div class="code-block mb-4">
                            <pre><code class="language-java">@EnableEurekaClient
@EnableFeignClients("com.qf.service")
@SpringBootApplication(scanBasePackages = "com.qf")
public class EurekaConsumerFeginApplication {
   public static void main(String[] args) {
      SpringApplication.run(EurekaConsumerFeginApplication.class, args);
   }
}</code></pre>
                        </div>
                        
                        <h4 class="font-medium mb-2">3. Feign接口</h4>
                        <div class="code-block mb-2">
                            <pre><code class="language-java">@FeignClient(name = "EUREKA-PROVIDE")
@RequestMapping(value = "/provider")
public interface HelloService {

    @RequestMapping(value = "/test1/{id}")
    String test1(@PathVariable("id") Integer id);

    @RequestMapping(value = "/addUser")
    public void addUser(@RequestBody User user);
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-6">
                    <h3 class="text-xl font-semibold mb-4">服务消费Ribbon和Feign区别</h3>
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h4 class="font-medium text-blue-600 mb-2">Ribbon</h4>
                            <p class="mb-4">Ribbon是一个基于HTTP客户端的负载均衡器，从Eureka注册中心获取服务端列表。</p>
                            <div class="bg-blue-50 p-4 rounded-lg">
                                <p class="text-sm text-blue-700">Ribbon需要开发者自己构建HTTP请求，并使用RestTemplate发送请求。</p>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-medium text-purple-600 mb-2">Feign</h4>
                            <p class="mb-4">Feign是在Ribbon的基础上进行了一次改进，是一个使用起来更加方便的HTTP客户端。</p>
                            <div class="bg-purple-50 p-4 rounded-lg">
                                <p class="text-sm text-purple-700">Feign采用接口的方式，只需要创建一个接口，然后在上面添加注解即可，将需要调用的其他服务的方法定义成抽象方法，不需要自己构建http请求。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Eureka Cluster -->
    <section id="eureka-cluster" class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 section-title">Eureka集群</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-8">
                    <p class="mb-6">之前配置的是单机版Eureka，这个时候Eureka服务挂了的话，那么我们的服务提供者跟服务消费者岂不是都废了？解决方案就是加集群，这里以3台Eureka为例。</p>
                    
                    <h3 class="text-xl font-semibold mb-4">集群配置</h3>
                    <div class="grid md:grid-cols-3 gap-6 mb-8">
                        <div class="bg-gray-100 p-4 rounded-lg">
                            <h4 class="font-medium mb-2">eureka8001</h4>
                            <div class="code-block-sm">
                                <pre><code>server:
  port: 8001
spring:
  application:
    name: eureka-server
eureka:
  client:
    fetch-registry: false
    register-with-eureka: false
    service-url:
      defaultZone: http://eureka8002.com:8002/eureka,http://eureka8003.com:8003/eureka</code></pre>
                            </div>
                        </div>
                        <div class="bg-gray-100 p-4 rounded-lg">
                            <h4 class="font-medium mb-2">eureka8002</h4>
                            <div class="code-block-sm">
                                <pre><code>server:
  port: 8002
spring:
  application:
    name: eureka-server2
eureka:
  client:
    fetch-registry: false
    register-with-eureka: false
    service-url:
      defaultZone: http://eureka8001.com:8001/eureka,http://eureka8003.com:8003/eureka</code></pre>
                            </div>
                        </div>
                        <div class="bg-gray-100 p-4 rounded-lg">
                            <h4 class="font-medium mb-2">eureka8003</h4>
                            <div class="code-block-sm">
                                <pre><code>server:
  port: 8003
spring:
  application:
    name: eureka-server3 
eureka:
  client:
    fetch-registry: false
    register-with-eureka: false
    service-url:
      defaultZone: http://eureka8001.com:8001/eureka,http://eureka8002.com:8002/eureka</code></pre>
                            </div>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mb-4">域名映射</h3>
                    <p class="mb-4">集群后三台Eureka服务的IP不一样，为了方便在本地测试，可以在hosts文件中做域名映射：</p>
                    <div class="code-block mb-6">
                        <pre><code>127.0.0.1 eureka8001.com
127.0.0.1 eureka8002.com
127.0.0.1 eureka8003.com</code></pre>
                    </div>
                    
                    <h3 class="text-xl font-semibold mb-4">注册服务</h3>
                    <p class="mb-4">发布的每一个服务都应该注册到所有的Eureka中：</p>
                    <div class="code-block">
                        <pre><code>server:
  port: 8082
spring:
  application:
    name: provider-server
eureka:
  client:
    service-url:
      defaultZone: http://eureka8001.com:8001/eureka,http://eureka8002.com:8002/eureka,http://eureka8003.com:8003/eureka</code></pre>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Hystrix -->
    <section id="hystrix" class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 section-title">断路器-Hystrix</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-8">
                    <h3 class="text-2xl font-semibold mb-4">什么是断路器</h3>
                    <p class="mb-6">当某个服务单元发生故障（类似用电器发生短路）之后，通过断路器的故障监控（类似熔断保险丝），向调用方返回一个错误响应，而不是长时间的等待。这样就不会使得线程因调用故障服务被长时间占用不释放，避免了故障在分布式系统中的蔓延造成的服务雪崩。</p>
                    
                    <h3 class="text-xl font-semibold mb-4">为什么微服务的故障会传递</h3>
                    <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692159155756-477c6e88-5481-49ac-98d0-972cb6e19485.png" alt="微服务故障传递" class="rounded-lg mb-6 w-full">
                    
                    <h3 class="text-xl font-semibold mb-4">Hystrix 断路机制</h3>
                    <div class="grid md:grid-cols-3 gap-6 mb-6">
                        <div class="bg-indigo-50 p-4 rounded-lg">
                            <h4 class="font-semibold text-indigo-700 mb-2">资源隔离</h4>
                            <p class="text-sm">Hystrix使用资源隔离模式（线程池或信号量）来防止故障扩散</p>
                        </div>
                        <div class="bg-green-50 p-4 rounded-lg">
                            <h4 class="font-semibold text-green-700 mb-2">降级</h4>
                            <p class="text-sm">当服务不可用时，自动调用本地降级方法返回合理默认值</p>
                        </div>
                        <div class="bg-red-50 p-4 rounded-lg">
                            <h4 class="font-semibold text-red-700 mb-2">熔断器</h4>
                            <p class="text-sm">当故障达到阈值时自动打开熔断，防止连锁故障</p>
                        </div>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h4 class="font-semibold mb-2">Ribbon整合Hystrix</h4>
                            <div class="code-block mb-4">
                                <pre><code class="language-java">@Controller
@RequestMapping("/ribbon")
public class RibbonTest {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/test")
    @ResponseBody
    @HystrixCommand(defaultFallback = "def") // 被动降级方法
    public String test(){
        String reuslt = restTemplate.getForObject("http://EUREKA-PROVIDER/provider/test/11", String.class);
        return "[ribbon result ] "+reuslt;
    }

    public String def(){
        return "服务调用失败，请稍后再试";
    }
}</code></pre>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-semibold mb-2">Feign整合Hystrix</h4>
                            <div class="code-block mb-2">
                                <pre><code class="language-java">@FeignClient(value = "EUREKA-PROVIDER",fallback = HelloServiceFallBack.class)
public interface IHelloService {
    @RequestMapping(value = "/provider/test/{id}")
    public String test(@PathVariable("id") Integer id);
}</code></pre>
                            </div>
                            <div class="code-block">
                                <pre><code class="language-java">@Component
public class HelloServiceFallBack implements IHelloService {
    @Override
    public String test(Integer id) {
        return id+":服务调用失败";
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-6">
                    <h3 class="text-xl font-semibold mb-4">Hystrix 监控</h3>
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <p class="mb-4">Hystrix提供了近实时的监控，实时记录所有关于HystrixCommand的执行信息，包括每秒执行多少请求多少成功，多少失败等。</p>
                            <div class="code-block mb-4">
                                <pre><code class="language-yaml">hystrix:
  command:
    default:
      circuitBreaker:
        enabled: true #是否开启熔断器
        requestVolumeThreshold: 2 #访问服务失败的次数
        sleepWindowInMilliseconds: 10000 #指定时间内进入半开状态</code></pre>
                            </div>
                        </div>
                        <div>
                            <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692159156050-43e8c4b5-6619-44bc-a680-f9799e2b17a6.png" alt="Hystrix Dashboard" class="rounded-lg">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Gateway -->
    <section id="gateway" class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 section-title">路由网关</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-8">
                    <h3 class="text-2xl font-semibold mb-4">什么是路由网关</h3>
                    <p class="mb-6">网关是系统的唯一对外的入口，介于客户端和服务器端之间的中间层，处理非业务功能，提供路由请求、鉴权、监控、缓存、限流等功能。它将"1对N"问题转换成了"1对1"问题。</p>
                    
                    <div class="grid md:grid-cols-2 gap-8 mb-6">
                        <div>
                            <h4 class="font-semibold mb-2">不使用网关的问题</h4>
                            <ul class="list-disc pl-5 space-y-2">
                                <li>客户端会多次请求不同微服务，增加了客户端复杂性</li>
                                <li>存在跨域请求，处理相对复杂</li>
                                <li>认证复杂，每个服务都需要独立认证</li>
                            </ul>
                        </div>
                        <div>
                            <h4 class="font-semibold mb-2">网关优点</h4>
                            <ul class="list-disc pl-5 space-y-2">
                                <li>路由转发：接收外界请求，转发到后端微服务</li>
                                <li>过滤器：完成权限校验、限流以及监控等</li>
                                <li>负载均衡：对后端服务进行负载均衡</li>
                            </ul>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mb-4">Spring Cloud Gateway配置</h3>
                    <div class="code-block mb-4">
                        <pre><code class="language-yaml">server:
  port: 8084
spring:
  application:
    name: eureka-getaway
  cloud:
    gateway:
      routes:
       - id: ribbon-consumer
         uri: lb://EUREKA-RIBBON
         predicates:
           - Path=/ribbon/**
         filters:
           - StripPrefix=1
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8080/eureka</code></pre>
                    </div>
                    
                    <h3 class="text-xl font-semibold mb-4">限流配置</h3>
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h4 class="font-medium mb-2">令牌桶算法</h4>
                            <p class="mb-4">当请求需要从桶中拿到令牌才能进行接口的访问，令牌桶会定时生成令牌放入桶中，请求过来需要经过这个桶，当从队列取得令牌后才能进行后续处理。</p>
                            <div class="code-block">
                                <pre><code class="language-yaml">spring:
  redis:
    host: 192.168.189.137
    password: root
  cloud:
    gateway:
      routes:
       - id: ribbon_consumer
         filters:
           - name: RequestRateLimiter
             args:
              key-resolver: '#{@myKeyResolver}'
              redis-rate-limiter.replenishRate: 1
              redis-rate-limiter.burstCapacity: 5</code></pre>
                            </div>
                        </div>
                        <div>
                            <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692159156777-94588859-125c-48ef-86b0-bb50be2d70f7.png" alt="令牌桶算法" class="rounded-lg mt-6">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Config -->
    <section id="config" class="py-16 px-4 md:px-0 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold mb-12 section-title">统一配置文件管理</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-8">
                    <h3 class="text-2xl font-semibold mb-4">配置文件服务端</h3>
                    <p class="mb-6">把所有微服务的配置文件都放到一个配置文件的管理中心(微服务)，当微服务启动的时候先到配置文件管理中心获取配置文件然后启动，这样就完成了微服务中集中式的配置文件管理。</p>
                    
                    <div class="grid md:grid-cols-2 gap-8 mb-6">
                        <div>
                            <h4 class="font-medium mb-2">Git配置方式</h4>
                            <div class="code-block">
                                <pre><code class="language-yaml">server:
  port: 8008
spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/dashixin/springcloud-config-server.git
          default-label: master
          search-paths: config</code></pre>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-medium mb-2">本地配置方式</h4>
                            <div class="code-block">
                                <pre><code class="language-yaml">server:
  port: 8008
spring:
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/config</code></pre>
                            </div>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mb-4">配置文件客户端</h3>
                    <div class="mb-6">
                        <p class="mb-2">Bootstrap.yml会优先于application.yml加载，因为配置文件在同一个地方管理，服务启动的时候先加载bootstrap.yml到配置中心加载对应的配置文件，然后再加载application.yml文件。</p>
                        <div class="code-block">
                            <pre><code class="language-yaml">spring:
  cloud:
    config:
      uri: http://localhost:8086 # configserver的访问地址
      name: application # 配置文件的名称
      profile: user # 配置文件的后缀</code></pre>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mb-4">配置文件热部署</h3>
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <p class="mb-2">在configserver修改了配置文件的信息后，客户端可以自动读取最新的配置信息。</p>
                            <div class="code-block mb-4">
                                <pre><code class="language-yaml">management:
  endpoints:
    web:
      exposure:
        include: ["*"]</code></pre>
                            </div>
                        </div>
                        <div>
                            <div class="code-block">
                                <pre><code class="language-java">@Controller
@RefreshScope
public class HelloController {
    @Value("${server.port}")
    private String port;
    
    @RequestMapping(value = "/hello")
    public String hello(){
        return "hello:"+port;
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-100 py-12">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-semibold mb-2">技术小馆</h3>
                    <p class="text-gray-400">探索技术前沿，分享开发知识</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition">访问技术小馆</a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```